<template>
  <div>
    <el-card shadow="always">
      <div>
        <div class="senior-search">
          <div slot="header" class="clearfix">
            <div v-if="findNot(arr2,item.classify)">
              <el-button style="float: right; padding: 3px 0" type="text" @click="downloadFile(item.content)"
                         v-if="find(downloadBtn,item.classify)"
              >下载
              </el-button>
              <el-button style="float: right; padding: 3px 0" type="text" @click="openUrl(item.content)"
                         v-else-if="find(arr4,item.classify)"
              >打开
              </el-button>
              <el-button style="float: right; padding: 3px 0" type="text" @click="openDialog" v-else>查看</el-button>
            </div>
            <span style="    cursor: pointer; " @click="openDialog">   {{ item.title }}</span>
          </div>
        </div>
        <NoteInfo v-if="open" :item="item" :open="open" @close="close"></NoteInfo>
      </div>

    </el-card>
  </div>
</template>

<script>
import music from './music'
import NoteInfo from '@/views/note/note/NoteInfo'
import {Base64} from "js-base64";

export default {

  name: 'NoteCard',
  props: ['item'],
  components: {NoteInfo, music},
  data() {
    return {
      arr2: [100],
      downloadBtn: [105, 107, 110, 111],
      arr4: [108],
      isCollapse: false,
      open: false,
      fullscreen: true,
      elCardStyle: ' padding: 0px;',
      image: '',
      videoOptions: {
        controls: true
      }
    }

  },
  created() {
    if (this.findNot(this.arr2,this.item.classify)){
      this.item.content=this.item.content ? Base64.decode(this.item.content) : null
      this.image = 'http://' + new URL(window.location.href).hostname + ':' + new URL(window.location.href).port + this.item.content
      console.log("转换的地址",this.image)
    }

  }
  , methods: {
    //查找某个元素是否存在
    find(arr, val) {
      let value = arr.indexOf(val)
      // console.log("find(arr,val){",value!==-1)
      return value !== -1
    },
    //查找某个元素是否不存在
    findNot(arr, val) {
      let value = arr.indexOf(val)
      // console.log("find(arr,val){",value!==-1)
      return value === -1
    },
    change() {
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {
        // this.elCardStyle = 'position: fixed;padding: 3px;'
      } else {
        // this.elCardStyle = 'padding: 3px;'
      }
    }, openDialog() {
      if (this.item.classify !== 100) {
        this.open = !this.open
        this.fullscreen = this.item.classify === 101
      }

    },
    downloadFile(fileUrl) {
      console.log("下载的地址",fileUrl)
      window.open(
        fileUrl
      )
    },
    openUrl(fileUrl) {
      window.open(
        fileUrl
      )
    },
    close() {
      this.open = false
    }

  }
}

</script>

<style scoped>

</style>
